﻿using OnlineAuction.Business;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineAuction
{
    public partial class Home : System.Web.UI.MasterPage
    {
        public string ck = "null";
        public string uRole = "User";
        public string ufn = "";
        public string l2m = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            //check cookie
            if (Request.Cookies["UserInfo"] == null) ck = "null";
            else
            {
                ck = Request.Cookies["UserInfo"]["UserName"];
                uRole = Request.Cookies["UserInfo"]["Role"];
                ufn = Request.Cookies["UserInfo"]["FullName"];
            }
            if (!Page.IsPostBack)
            {
                if (Request.Cookies["UserInfo"] == null) ck = "null";
                else
                {
                    ck = Request.Cookies["UserInfo"]["UserName"];
                    uRole = Request.Cookies["UserInfo"]["Role"];
                    if (uRole == "User")
                    {
                        l2m = @"Users/ManageHome.aspx";
                    }
                    else
                    {
                        l2m = @"Admin/ManageHome.aspx";
                    }
                }
                //Get all category
                CategoryBO categoryBO = new CategoryBO();
                ddlCategoryName.DataTextField = "CategoryName";
                ddlCategoryName.DataValueField = "CategoryID";
                var Category = categoryBO.GetCategory();
                ddlCategoryName.DataSource = Category;
                ddlCategoryName.DataBind();
                gvMenuLeft.DataSource = Category;
                gvMenuLeft.DataBind();
            }
        }

        protected void brnSearch_Click(object sender, EventArgs e)
        {
            Response.Redirect("Home.aspx?ItemName=" + txtSearch.Text + "&CategoryID=" + ddlCategoryName.SelectedValue);
        }

        protected void gvMenuLeft_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            Response.Redirect("Home.aspx?ItemName=&CategoryID=" + e.CommandName);
        }
    }
}